package com.js.admin.controller;

import com.js.admin.entity.BaseTenant;
import com.js.admin.entity.BaseUser;
import com.js.admin.service.BaseTenantService;
import com.js.admin.service.BaseUserService;
import com.js.auth.client.annotation.CheckUserToken;
import com.js.common.controller.BaseController;
import com.js.common.response.ObjectRestResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author ygl
 * @create 2018-11-06
 * @DESCRIPTION
 **/
@CheckUserToken
@Api(tags="租户模块")
@RestController
@RequestMapping("tenant")
public class BaseTenantController extends BaseController<BaseTenant,String> {

    @Autowired
    private BaseTenantService baseTenantService;

    @Autowired
    private BaseUserService baseUserService;

    @ApiOperation("租户授予用户")
    @PutMapping("/{id}/user")
    public ObjectRestResponse<Boolean> updateUser(@PathVariable("id") String id, String userId){
        baseTenantService.updateUser(id,userId);
        return new ObjectRestResponse<>();
    }

    @ApiOperation("获取租户授予用户")
    @GetMapping("/{id}/user")
    public ObjectRestResponse<BaseUser> updateUser(@PathVariable("id") String id){
        BaseTenant tenant = baseTenantService.selectById(id);
        return new ObjectRestResponse<>().data(baseUserService.selectById(tenant.getOwner()));
    }

}
